<?php
/**
* @version		$Id: view.html.php 10381 2008-06-01 03:35:53Z pasamio $
* @package		Joomla
* @subpackage	Users
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the Users component
 *
 * @static
 * @package		Joomla
 * @subpackage	Users
 * @since 1.0
 */
class BanwordsViewBanwords extends JView
{
	function display($tpl = null)
	{
		global $mainframe, $option;

		$db				=& JFactory::getDBO('shaishaidb');
		$currentUser	=& JFactory::getUser();//获取当前用户类
		$acl			=& JFactory::getACL();//获取授权信息

		$filter_order		= $mainframe->getUserStateFromRequest( "$option.filter_order",		'filter_order',		'a.id',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( "$option.filter_order_Dir",	'filter_order_Dir',	'',			'word' );
//		$filter_type		= $mainframe->getUserStateFromRequest( "$option.filter_type",		'filter_type', 		0,			'string' );//过滤类型
//		$filter_logged		= $mainframe->getUserStateFromRequest( "$option.filter_logged",		'filter_logged', 	0,			'int' );
		$search				= $mainframe->getUserStateFromRequest( "$option.search",			'search', 			'',			'string' );
		$search				= JString::strtolower( $search );//获取search域中的信息

		$limit		= $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
		$limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );

		$wheres = array();
		if (isset( $search ) && $search!= '')
		{
			$searchEscaped = $db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
			$wheres[] = 'a.banword LIKE '.$searchEscaped;//
		}
		

		// exclude any child group id's for this user//
//		$pgids = $acl->get_group_children( $currentUser->get('gid'), 'ARO', 'RECURSE' );
//
//		if (is_array( $pgids ) && count( $pgids ) > 0)
//		{
//			JArrayHelper::toInteger($pgids);
//			$where[] = 'a.gid NOT IN (' . implode( ',', $pgids ) . ')';
//		}
//		$filter = '';
//		if ($filter_logged == 1 || $filter_logged == 2)
//		{
//			$filter = ' INNER JOIN #__session AS s ON s.userid = a.id';
//		}
        
		$orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir;
		$where = ( count( $wheres ) ? ' WHERE (' . implode( ') AND (', $wheres ) . ')' : '' );

		$query = 'SELECT COUNT(a.id)'
		. ' FROM banwords AS a'
		. $where
		;
		$db->setQuery( $query );
		$total = $db->loadResult();//数目
//        $wheres[] = 'a.id = b.user_id';
//        $where = ( count( $wheres ) ? ' WHERE (' . implode( ') AND (', $wheres ) . ')' : '' );
		jimport('joomla.html.pagination');
		$pagination = new JPagination( $total, $limitstart, $limit );
        
		$query = 'SELECT * '
			. ' FROM banwords AS a'
			. $where
//			. ' GROUP BY a.id'
			. $orderby
		;
		$db->setQuery( $query, $pagination->limitstart, $pagination->limit );
		$rows = $db->loadObjectList();//获取所有列

//		$n = count( $rows );
//		$template = 'SELECT COUNT(s.userid)'
//			. ' FROM #__session AS s'
//			. ' WHERE s.userid = %d'
//		;
//		for ($i = 0; $i < $n; $i++)
//		{
//			$row = &$rows[$i];
//			$query = sprintf( $template, intval( $row->id ) );
//			$db->setQuery( $query );//判断该用户是否登录
//			$row->loggedin = $db->loadResult();
//		
//		// 是否登录select列表
//		$logged[] = JHTML::_('select.option',  0, '- '. JText::_( 'Select Log Status' ) .' -');
//		$logged[] = JHTML::_('select.option',  1, JText::_( 'Logged In' ) );
//		$lists['logged'] = JHTML::_('select.genericlist',   $logged, 'filter_logged', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_logged" );

		// table ordering
		$lists['order_Dir']	= $filter_order_Dir;
		$lists['order']		= $filter_order;

		// search filter
		$lists['search']= $search;

		$this->assignRef('user',		JFactory::getUser());
		$this->assignRef('lists',		$lists);
		$this->assignRef('items',		$rows);
		$this->assignRef('pagination',	$pagination);

		parent::display($tpl);
	}
}